package com.mt.channel.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.channel.entity.ChannelMsgLogEntity;
import com.mt.channel.mapper.ChannelMsgLogEntityMapper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;

@Component
public class ChannelMsgLogServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelMsgLogServiceModel.class);

    @Autowired
    private ChannelMsgLogEntityMapper channelMsgLogEntityMapper;

    public ServiceResult<List<ChannelMsgLogEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.channelMsgLogEntityMapper, "Property 'channelMsgLogEntityMapper' is required.");
        ServiceResult<List<ChannelMsgLogEntity>> result = new ServiceResult<List<ChannelMsgLogEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            result.setResult(this.channelMsgLogEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMsgLogServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ChannelMsgLogEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.channelMsgLogEntityMapper, "Property 'channelMsgLogEntityMapper' is required.");
        ServiceResult<ChannelMsgLogEntity> result = new ServiceResult<ChannelMsgLogEntity>();
        try {
            result.setResult(this.channelMsgLogEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMsgLogServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ChannelMsgLogEntity channelMsgLogEntity) {
        Assert.notNull(this.channelMsgLogEntityMapper, "Property 'channelMsgLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelMsgLogEntityMapper.insert(channelMsgLogEntity);
            if (save > 0) {
                id = channelMsgLogEntity.getChannelMsgLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMsgLogServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ChannelMsgLogEntity channelMsgLogEntity) {
        Assert.notNull(this.channelMsgLogEntityMapper, "Property 'channelMsgLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelMsgLogEntityMapper.updateByPrimaryKeySelective(channelMsgLogEntity);
            if (save > 0) {
                id = channelMsgLogEntity.getChannelMsgLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMsgLogServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ChannelMsgLogEntity channelMsgLogEntity) {
        Assert.notNull(this.channelMsgLogEntityMapper, "Property 'channelMsgLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelMsgLogEntityMapper.updateByPrimaryKeySelective(channelMsgLogEntity);
            if (save > 0) {
                id = channelMsgLogEntity.getChannelMsgLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMsgLogServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer channelMsgLogId) {
        Assert.notNull(this.channelMsgLogEntityMapper, "Property 'channelMsgLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.channelMsgLogEntityMapper.deleteByPrimaryKey(channelMsgLogId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelMsgLogServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
